package com.mfangsoft.zhuangjialong.integration.order.contrller;





import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.beanutils.BeanMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mfangsoft.zhuangjialong.common.context.UserContext;
import com.mfangsoft.zhuangjialong.common.model.Page;
import com.mfangsoft.zhuangjialong.common.model.ResponseMessage;
import com.mfangsoft.zhuangjialong.common.utils.SysConstant;
import com.mfangsoft.zhuangjialong.integration.order.model.BaseOrder;
import com.mfangsoft.zhuangjialong.integration.order.model.OrderExplain;
import com.mfangsoft.zhuangjialong.integration.order.model.OrderInfo;
import com.mfangsoft.zhuangjialong.integration.order.service.IOrderService;
import com.mfangsoft.zhuangjialong.integration.user.model.UserEntity;




@Controller
@RequestMapping("/server")
public class OrderController {
	
	@Autowired
	private IOrderService orderService; 
	
	/**
	 * 订单列表
	 * @param baseActivityInfo
	 * @return
	 */
	
	@RequestMapping(value="/selectOrderPage",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<Map<String,Object>>> selectOrderPage(@RequestBody Page<Map<String,Object>> page){
		ResponseMessage<Page<Map<String,Object>>> message = new ResponseMessage<Page<Map<String,Object>>>();
		try {
			message.setResult(orderService.selectOrderPage(page));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
	}
	
	@RequestMapping(value="/selectOrderDetail",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<OrderInfo> selectOrderDetail(@RequestBody Integer orderId){
		ResponseMessage<OrderInfo> message = new ResponseMessage<OrderInfo>();
		try {
			message.setResult(orderService.selectOrderDetail(orderId));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
	}
	
	@RequestMapping(value="/updateOrderStatus",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> updateOrderStatus(@RequestBody OrderInfo order){
		ResponseMessage<String> message = new ResponseMessage<String>();
		try {
			orderService.updateOrderStatus(order);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	
	@RequestMapping(value="/addOrderExplain",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> addOrderExplain(@RequestBody OrderExplain orderExplain){
		ResponseMessage<String> message = new ResponseMessage<String>();
		try {
			orderService.addOrderExplain(orderExplain);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	
	@RequestMapping(value="/updateExplain",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> updateExplain(@RequestBody OrderExplain orderExplain){
		ResponseMessage<String> message = new ResponseMessage<String>();
		try {
			orderService.updateExplain(orderExplain);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	@RequestMapping(value="/selectExplain",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<OrderExplain> selectExplain(){
		ResponseMessage<OrderExplain> message = new ResponseMessage<OrderExplain>();
		try {
			OrderExplain explain = orderService.selectExplain();
			message.setResult(explain);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	
	@RequestMapping(value="/updateOrder",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> updateOrder(@RequestBody OrderInfo order){
		ResponseMessage<String> message = new ResponseMessage<String>();
		try {
			orderService.updateOrder(order);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	@RequestMapping(value="/selectOrderTotalMoney",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Map<String,Object>> selectOrderTotalMoney(@RequestBody Map<String,Object> map){
		ResponseMessage<Map<String,Object>> message = new ResponseMessage<Map<String,Object>>();
		try {
			message.setResult(orderService.selectOrderTotalMoney(map));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
}
